package com.hc.usb.impl;

public class USBBytesUtil {
    public static String toString(byte[] buffer){
        int i=0;
        for (; i < buffer.length; i++) {
            if((buffer[i] & 0xff)==0x20){
                break;
            }
        }
        return new String(buffer,0,i);
    }

    public static byte getCheckSum(byte[] data){
        int sum = 0;
        for (int i = 0; i < 11; i++) {
            sum = ((sum & 1)==1?0x80:0) + ((sum &0xff)>> 1) + data[i];
        }
        byte checksum = (byte) (sum & 0xff);
        return checksum;
    }
}
